#include "pagejump.h"


#include "singletonroot.h"

#include <QVBoxLayout>



PageJump::PageJump(QObject *parent) : QObject(parent)
{

}

void PageJump::home(bool isAdmin)
{
//    setPage(nullptr);
//    m_pWgt->hide();
    setPage("");
    if(isAdmin){
        m_pTopAdmin->show();
        m_pTopUser->hide();
    }else{
        m_pTopUser->show();
        m_pTopAdmin->hide();
    }

    //    GDATA->isAdmin = !GDATA->isAdmin;
}



void PageJump::setPage(const QString &page)
{

    auto curPage =  getPage(page);
    for(auto otherPage:m_subPage){
        otherPage->setVisible(otherPage == curPage);
    }

    if(curPage){
        if(conterWgt) conterWgt->show();
    }else{
        if(conterWgt) conterWgt->hide();
    }
}

QWidget *PageJump::getPage(const QString &page)
{
    if(!m_subPage.contains(page)){

        auto pageWgt = factory.createWid(page);

        if(!pageWgt){
            return nullptr;
        }

        pageWgt->hide();

        pageWgt->setStyleSheet("");


        m_subPage.insert(page,pageWgt);

        layout->addWidget(pageWgt);
    }
    return m_subPage.value(page);
}



QWidget *PageJump::pTopUser() const
{
    return m_pTopUser;
}

void PageJump::setPTopUser(QWidget *newPTopUser)
{
    m_pTopUser = newPTopUser;
}

QWidget *PageJump::pTopAdmin() const
{
    return m_pTopAdmin;
}

void PageJump::setPTopAdmin(QWidget *newPTopAdmin)
{
    m_pTopAdmin = newPTopAdmin;
}

QVBoxLayout *PageJump::getLayout() const
{
    return layout;
}

void PageJump::setLayout(QVBoxLayout *newLayout)
{
    layout = newLayout;
}

QString PageJump::qss()
{
    QString str = R"(
background:rgba(255,255,255,200);
border:4px;
)";

    return str;
}

QWidget *PageJump::getConterWgt() const
{
    return conterWgt;
}

void PageJump::setConterWgt(QWidget *newConterWgt)
{
    conterWgt = newConterWgt;
}
